home *** CD-ROM | disk | FTP | other *** search
/ Risc World 3 / Risc World 3.iso / SOFTWARE / ISSUE6 / PD / PDF / GuiLib / Util / c++ / file next >
Text File  |  2003-02-14  |  3KB  |  97 lines

  1. //--------------------------------------------------------------------------
  2. //
  3. //   Copyright (c) 2002, Colin Granville
  4. //
  5. //   All rights reserved.
  6. //
  7. //   Redistribution and use in source and binary forms, with or
  8. //   without modification, are permitted provided that the following 
  9. //   conditions are met:
  10. //
  11. //      * Redistributions of source code must retain the above copyright 
  12. //        notice, this list of conditions and the following disclaimer.
  13. //
  14. //      * Redistributions in binary form must reproduce the above 
  15. //        copyright notice, this list of conditions and the following 
  16. //        disclaimer in the documentation and/or other materials 
  17. //        provided with the distribution.
  18. //
  19. //      * The name Colin Granville may not be used to endorse or promote 
  20. //        products derived from this software without specific prior 
  21. //        written permission.
  22. //
  23. //   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
  24. //   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
  25. //   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
  26. //   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
  27. //   COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
  28. //   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  29. //   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  30. //   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
  31. //   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  32. //   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  33. //   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
  34. //   OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. //--------------------------------------------------------------------------
  37.  
  38. #include "file.h"
  39. #include "swis.h"
  40.  
  41.  
  42. // returns file_type or len if int* 's !=0
  43. bool isFile(const char* filename, int *filetype,int *length)
  44. {
  45.   DirectoryObject obj_type=fileInfo(filename,filetype,length);
  46.   return obj_type==Dob_File;
  47. }
  48.  
  49. //***********************************************************
  50.  
  51. DirectoryObject fileInfo(const char* filename,int *file_type,int *length)
  52. {
  53.   int len,load;
  54.   DirectoryObject object_type=Dob_NotFound;
  55.   if (_swix(OS_File,_INR(0,1) | _OUT(0) |_OUT(2) | _OUT(4),
  56.                  5,filename,&object_type,&load,&len)==0)
  57.      {
  58.      if (file_type) *file_type=((load>>8) & 0xfff);
  59.      if (length) *length=len;
  60.      }
  61.   return object_type;
  62. }
  63.  
  64. //***********************************************************
  65.  
  66. bool isDirectory(const char* dirname)
  67. {
  68.   DirectoryObject dir_o=fileInfo(dirname);
  69.   return dir_o==Dob_Directory || dir_o==Dob_ImageFile;
  70. }
  71.  
  72. //***********************************************************
  73.  
  74. void setFileType(const char*filename, int type)
  75. {
  76.   if (type==0xdeaddead)
  77.      {
  78.      //set load and exec addresses to 0xdeaddead used while file is loading
  79.      _swix(OS_File,_INR(0,2),2,filename,type);
  80.      _swix(OS_File,_INR(0,1)|_IN(3),3,filename,type);
  81.      }
  82.   else
  83.      {
  84.      _swix(OS_File,_INR(0,2),18,filename,type);
  85.      }
  86. }
  87.  
  88. //***********************************************************
  89.  
  90. bool createDirectory(const char* dirname)
  91. {
  92.    return (_swix(OS_File,_INR(0,1) | _IN(4),8,dirname,0)==0);
  93. }
  94.  
  95.  
  96.  
  97.